# Contributor: Iskren Chernev <me@iskren.info>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Iskren Chernev <me@iskren.info>
pkgname=py3-jsonschema417
pkgver=4.17.3
pkgrel=1
pkgdesc="An implementation of JSON Schema validation for Python"
url="https://github.com/python-jsonschema/jsonschema"
arch="noarch"
license="MIT"
depends="python3 py3-pyrsistent py3-attrs"
makedepends="
	py3-gpep517
	py3-hatch-fancy-pypi-readme
	py3-hatch-vcs
	py3-hatchling
	py3-installer
	py3-setuptools_scm
	py3-wheel
	"
checkdepends="py3-twisted py3-pytest"
subpackages="$pkgname-pyc"
source="https://files.pythonhosted.org/packages/source/j/jsonschema/jsonschema-$pkgver.tar.gz
	"
builddir="$srcdir/jsonschema-$pkgver"

prepare() {
	default_prepare
	find . -name '*.py' -exec \
		sed -i \
			-e 's/import jsonschema$/import jsonschema417 as jsonschema/' \
			-e 's/import jsonschema[.]/import jsonschema417./' \
			-e 's/from jsonschema/from jsonschema417/' '{}' \;
	mv jsonschema jsonschema417
	sed -i 's/name = "jsonschema"/name = "jsonschema417"/' pyproject.toml
	# cli doesn't work as of now, it's also deprecated
	rm jsonschema417/tests/test_cli.py
	rm jsonschema417/tests/test_deprecations.py
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m twisted.trial jsonschema417
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/jsonschema417-$pkgver-py3-none-any.whl

	# Add version suffix to executable files.
	local path; for path in "$pkgdir"/usr/bin/*; do
		mv "$path" "$path"-3
	done

	ln -s $pkgname-3 "$pkgdir"/usr/bin/jsonschema
}

sha512sums="
626fc913c37d2e49e4b47c9e058aab4a96c1dc50c35d8def0b2ea0ca464dc25e3318d4fde4927c11ca38068743cd81779d5189464b821407ac1de1788bad30e2  jsonschema-4.17.3.tar.gz
"
